% !TEX TS-program = xelatex
% !TEX encoding = UTF-8

\documentclass[
a4paper,
10pt,
%twocolumn
]{paper}
\usepackage[colorlinks,
linkcolor=blue,
citecolor=blue,
urlcolor=magenta,
pdftitle={ClassMC},
pdfauthor={Youhua Xu}]{hyperref}
\usepackage{bm}
\usepackage{caption}
\usepackage{algorithm}
% \usepackage{xcolor}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{calc}
\usepackage{graphicx}
\usepackage{bookmark}
\usepackage[T1]{fontenc}

\setlength\textwidth{7in}
\setlength\textheight{10in}
\setlength\oddsidemargin{(\paperwidth-\textwidth)/2 - 1in}
\setlength\topmargin{(\paperheight-\textheight-\headheight-\headsep-\footskip)/2 - 1 in}

\usepackage{listings} % Required for inserting code snippets
\usepackage[usenames,dvipsnames]{color} % Required for specifying custom colors and referring to colors by name

\definecolor{DarkGreen}{rgb}{0.0,0.4,0.0} % Comment color
\definecolor{highlight}{RGB}{255,251,204} % Code highlight color

\lstdefinestyle{Style1}{ % Define a style for your code snippet, multiple definitions can be made if, for example, you wish to insert multiple code snippets using different programming languages into one document
language=C++, % Detects keywords, comments, strings, functions, etc for the language specified
backgroundcolor=\color{highlight}, % Set the background color for the snippet - useful for highlighting
basicstyle=\footnotesize\ttfamily, % The default font size and style of the code
breakatwhitespace=false, % If true, only allows line breaks at white space
breaklines=true, % Automatic line breaking (prevents code from protruding outside the box)
captionpos=b, % Sets the caption position: b for bottom; t for top
commentstyle=\usefont{T1}{pcr}{m}{sl}\color{DarkGreen}, % Style of comments within the code - dark green courier font
deletekeywords={}, % If you want to delete any keywords from the current language separate them by commas
%escapeinside={\%}, % This allows you to escape to LaTeX using the character in the bracket
firstnumber=1, % Line numbers begin at line 1
frame=single, % Frame around the code box, value can be: none, leftline, topline, bottomline, lines, single, shadowbox
frameround=tttt, % Rounds the corners of the frame for the top left, top right, bottom left and bottom right positions
keywordstyle=\color{Blue}\bf, % Functions are bold and blue
morekeywords={}, % Add any functions no included by default here separated by commas
numbers=left, % Location of line numbers, can take the values of: none, left, right
numbersep=10pt, % Distance of line numbers from the code box
numberstyle=\tiny\color{Gray}, % Style used for line numbers
rulecolor=\color{black}, % Frame border color
showstringspaces=false, % Don't put marks in string spaces
showtabs=false, % Display tabs in the code as lines
stepnumber=5, % The step distance between line numbers, i.e. how often will lines be numbered
stringstyle=\color{Purple}, % Strings are purple
tabsize=2, % Number of spaces per tab in the code
}

% Create a command to cleanly insert a snippet with the style above anywhere in the document
\newcommand{\insertcode}[2]{\begin{itemize}\item[]\lstinputlisting[caption=#2,label=#1,style=Style1]{#1}\end{itemize}}
% The first argument is the script location/filename and the second is a caption for the listing


\begin{document}

\title{ClassMC}
\author{Youhua Xu}
\date{\today}

\maketitle


\begin{abstract}
ClassMC is a cosmological parameter extract package, composed of CLASS and IMCMC. This document
explains the structure of ClassMC, communications between CLASS and IMCMC and how to add more extensions.
\end{abstract}

% \newpage
\tableofcontents
% \newpage


\section{Introduction}
\textit{Why ClassMC?} The reason is simple: I personaly prefer using C/C++ to write programs for cosmological
and other applications. I believe many others, who use C/C++ in their daily life but are not familiar with
Fortran, are likely to feel the same way.

\subsection{Prerequistes and installation}
ClassMC is build on CLASS written by JL and IMCMC written by XYH. CLASS is purely coded in C (and a C++ interface),
and it uses only the standard libraries; IMCMC is written in C++, and it uses an external library, the GNU Scientific
Library (GSL), from which the random number generation engine(s) is used.


\section{Play with CLASS}

\subsection{ClassEngine: a C++ interface to CLASS}
ClassEngine provides a very convenient way to use CLASS inside C++ programs, although some small bugs must be fixed
before it is used in practise (see section~\ref{classengine_bugfix} for more details).

\subsection{Implementing new models in CLASS}


\section{Design of IMCMC}


\section{Datasets and Likelihoods}


\insertcode{"example_codes/data.cpp"}{Example of a dataset.}

\insertcode{"example_codes/like.cpp"}{Example of a likelihood.}

\section{Communication between IMCMC and CLASS}
\insertcode{"example_codes/DataList.hpp"}{DataList.hpp}

\insertcode{"example_codes/ParamList.hpp"}{ParamList.hpp}


\appendix

\section{Bug-fix inside ClassEngine} \label{classengine_bugfix}


\section{Extracting parameters and making beautiful plots with GetDist}
The Python package GetDist written by Anthony Lewis is an amazing tool for parameter extraction (estimation) from
chain files generated by a MCMC sample (e.g., IMCMC and CosmoMC) and making various beautiful plots.

\section{Cosmological parameter choices for different datasets}
E.g, $Y_P$ (or $Y_{He}$) can be constrained using standard BBN theory or from CMB power spectrum
directly (see Planck2015). In the former, $Y_P$ is determined from $\omega_b$ and some other parameters,
so in this case, $Y_P$ \textit{should} not be treated as a MCMC parameter.

\section{Useful resources for Fortran and C/C++ mixed programming}
Some datasets and likelihood functions are written in Fortran language, so mixed programming in
Fortran and C/C++ is necessary.  The following are some useful references on how to cooperate
Fortran with C/C++ :

\begin{itemize}
\item \url{http://www.neurophys.wisc.edu/comp/docs/not017/}
\item \url{https://computing.llnl.gov/tutorials/linux_clusters/mixedProgramming1.pdf}
\item \url{http://www.cae.tntech.edu/help/programming/mixed_languages}
\end{itemize}


\end{document}
